filter function is not working and giving errors